<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        }
        .jokes {
            width: 800px;
            height: 800px;
            margin: 100px auto;
            background: url(./image/bean01.png) no-repeat;
            background-size: 100%;
            color:yellowgreen;
            padding: 30px;
        }
        .jokes span {
            font-size: 25px;
            color:pink;
        }
        .jokes button {
           margin-left: 20px;
           font-size: 20px;
           color: skyblue;
           border: 1px solid greenyellow;
        }
        .jokes-text {
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="jokes">
        <span>开心一笑</span><button>点我换一个</button>
         <div class="jokes-text"></div>
    </div>
    <script src="./js/jquery-1.12.4.min.js"></script>
    <script>
        $(function(){
           function showJokes() {
            $('.jokes-text').text('加载中。。。')
            $.ajax({
                type:'get',
                url:'https://autumnfish.cn/api/joke',
                success:function(backData){
                 $('.jokes-text').text(backData)
                }
            })
           }
           showJokes();
         let timeId= setInterval(showJokes,5000)
            $('button').on('click',function(){
                clearInterval(timeId)
                $('.jokes-text').text('加载中...')
                $.ajax({
                type:'get',
                url:'https://autumnfish.cn/api/joke',
                success:function(backData){
                 $('.jokes-text').text(backData)
                }
            })
            })
            $('button').on('mouseleave',function(){
                debugger
                showJokes();
                timeId= setInterval(showJokes,5000)
            })
        })
    </script>
</body>
</html>